#ifndef BASELOADER_H
#define BASELOADER_H

#include "article5common.h"

class BaseLoader
{
protected:
    QSqlQuery _sqlQuery;

    QString _queryBuffer;
    uint _queryBufferCapacity;
    uint _numOfQueries;
    QString _tableLastQuery;

    // (tamanho da consulta, numero de consultas imbutidas)
    // para avaliar corretamente o tamanho das consultas
    QueryList _queryList;

    QString _serialize(const QList<QString>& element);
    void _insertHeader(const QString& table);
    bool _finalizeQuery();

    bool _executeQuery();

public:
    BaseLoader(const QString &user, const QString &passwd, uint bufferCapacity);
    virtual ~BaseLoader();

    bool addEdgeElement(EdgeElement& e);
    bool addPathElement(const QString& path, uint id);

    void getFinalData(quint64& acBufferSize, quint64& acNumberQueries, uint& numOfDbAccess);

    virtual QString serialize(EdgeElement& e) const;
    virtual EdgeElement* newElement(EdgeElement* parent, uint id, const QString& value, uint path_id, bool attribute) const = 0;
    QString getLastLabel(const QString& path);
    void loadEdgeElement(const QSqlRecord& record, EdgeElement* element);

    virtual uint getAdditionalTime() { return 0; }

};

#endif // BASELOADER_H
